//
//  HJBuyBottom.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJBuyBottom.h"
#import "HJHomeModel.h"

@interface HJBuyBottom()

@property (weak, nonatomic) IBOutlet UIView *line;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionH;/**各种说明Label高*/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionLayoutH;/**各种说明视图总高*/
@property (weak, nonatomic) IBOutlet UILabel *instruction;/**s说明*/

@end
@implementation HJBuyBottom
-(void)awakeFromNib {
    [super awakeFromNib];
    self.consignee.font = HJFontSize(mScreenWidth/414 *15);
    self.adress.font = HJFontSize(mScreenWidth/414 *15);
    self.phoneNo.font = HJFontSize(mScreenWidth/414 *15);
    self.AdressL.font = HJFontSize(mScreenWidth/414 *15);
    self.instruction.font = HJFontSize(mScreenWidth/414 *15);
}
-(instancetype)init{
    if (self = [super init]) {
        self= [[NSBundle mainBundle]loadNibNamed:@"HJBuyBottom" owner:nil options:nil].firstObject;
    }
    return self;
}
-(void)setModel:(HJOderModel *)model {
    _model = model;
    if (self.tag==100) {
        self.buyTimeH.constant = 0.001;
        [self.buyBottomBtn setTitle:[NSString stringWithFormat:@"去付款(￥%@)",model.shoes.reference_price] forState:UIControlStateNormal];
        [self.buyBottomBtn setBackgroundColor:HJColor(255, 72, 74)];
    }
    if (model.address) {
        self.AdressL.hidden =YES;
        self.consignee.text = [NSString stringWithFormat:@"收货人：%@",model.address.name];
        self.phoneNo.text = [NSString stringWithFormat:@"手机号：%@",model.address.mobile];
        self.adress.text = [NSString stringWithFormat:@"地   址：%@%@",model.address.address,model.address.detail_address];
    }else {
        self.AdressL.hidden = NO;
//        self.consignee.hidden = YES;
//        self.phoneNo.hidden = YES;
//        self.adress.hidden = YES;
    }
    
    self.instruction.text = model.trade_detail;
    self.instructionH.constant = model.trade_H-40;
    self.instructionLayoutH.constant = model.trade_H +116;
    _address_id = model.address.address_id;
}
//3 7 15天 tag==3 4 5
- (IBAction)timeBtn:(UIButton *)sender {
    [self animationLineWithBtn:sender];
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    if (sender.tag==5) {
        dic[@"days"] = @"15";
    }else if (sender.tag==4) {
        dic[@"days"] = @"7";
    }else {
        dic[@"days"] = @"3";
    }
    [mNotificationCenter postNotificationName:@"timeNotification" object:nil userInfo:dic];
}
// 滑动线条
-(void)animationLineWithBtn:(UIButton *)btn {
    for (int i = 3; i<=5; i ++) {
        UIView *view = [self viewWithTag:i];
        view.alpha = 0.5;
    }
    btn.alpha = 1;
    [UIView animateWithDuration:0.1 animations:^{
        _line.centerX = btn.centerX;
    }];
}
/**收货地址跳转按钮*/
- (IBAction)consigneeAdressBtn:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"consigneeAdresBtn" object:nil];
}


// 底部按钮
- (IBAction)buyBottomBtn:(UIButton *)sender {
    NSDictionary *dic =[NSDictionary dictionary];
    if ([sender.titleLabel.text isEqualToString:@"立刻求购"]) {
        dic = @{@"tag":@"0"};
    }else {
        dic = @{@"tag":@"1"};
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"buyBottomBtn" object:nil userInfo:dic];
}
-(void)setAddress_id:(NSString *)address_id {
    _address_id = address_id;
}
@end
